 

 \section{链表}

		%\begin{tikzpicture}[state/.style=state with output]
	%	
	%	\foreach \i in {0,...,5} {
		%		\pgfmathsetmacro{\randomX}{rand*10-5}
		%		\pgfmathsetmacro{\randomY}{rand*10-5}
		%		\checkOverlap{\randomX}{\randomY}{\i}
		%		\ifnum\i>0
		%		\node[state] (q\i) at (\randomX,\randomY) {$q_{\i}$ \nodepart{lower} \randomX,\randomY};
		%		\else
		%		\node[state] (q0) at (\randomX,\randomY) {$q_{\i}$ \nodepart{lower} \randomX,\randomY};
		%		\fi
		%	}
	%	
	%\end{tikzpicture}

	\subsection{单链表}
	\usetikzlibrary {automata}
	\begin{tikzpicture}[state/.style=state with output]
			\foreach \i in {0,...,5} {
				\pgfmathsetmacro{\randomX}{rand*5-2}
				\pgfmathsetmacro{\randomY}{rand*5-1}
				\node[state]  at (\randomX,\randomY) {$q_{\i}$ \nodepart{lower} 0f000{\i}};
				%\node[state]  at (\randomX,\randomY) {$q_{\i}$ \nodepart{lower}  0f000\i};
			}

	\end{tikzpicture}
	
	\begin{tikzpicture}[->,>=stealth,node distance=2cm, auto]
		\tikzstyle{nodestyle}=[draw, circle, minimum size=1cm, inner sep=0pt]
		
		\node [nodestyle] (q0) at (-2,0) {q0}; % 新增节点0
		\node [nodestyle] (q1) at (0,0) {q1};
		\node [nodestyle, right of=q1] (q2) {q2};
		\node [nodestyle, right of=q2] (q3) {q3};
		\node [nodestyle, right of=q3] (null) {null};
		
		\draw[->] (q0) -- node[above=0.2cm, align=center] {next} (q1); % 添加从q0到q1的箭头
		\draw[->] (q1) -- node[above=0.2cm, align=center] {next} (q2);
		\draw[->] (q2) -- node[above=0.2cm, align=center] {next}  (q3);
		\draw[->] (q3) -- node[above=0.2cm, align=center] {next}  (null);
	\end{tikzpicture}
	
	
	\subsubsection{链表中存在回文}
	\begin{tikzpicture}[->,>=stealth,node distance=2cm, auto]
				\tikzstyle{nodestyle}=[draw, circle, minimum size=1cm, inner sep=0pt]
		
		\begin{scope}
			\node [nodestyle] (n1) {1};
			\node [nodestyle,right of=n1] (n2) {2};
			\node [nodestyle,right of=n2] (n3) {3};
			\node [nodestyle,right of=n3] (n4) {2};
			\node [nodestyle,right of=n4] (n5) {1};
			\node [nodestyle, right of=n5] (n6) {null};
			
			\draw[->] (n1) --node[above=0.2cm,align=center] {next} (n2);
			\draw[->] (n2) --node[above=0.2cm,align=center] {next} (n3);
			\draw[->] (n3) --node[above=0.2cm,align=center] {next} (n4);
			\draw[->] (n4) --node[above=0.2cm,align=center] {next} (n5);
			\draw[->] (n5) --node[above=0.2cm,align=center] {next} (n6);
		\end{scope}

		\begin{scope}[yshift=-3cm]
			\node [nodestyle] (n1) {1};
			\node [nodestyle,right of=n1] (n2) {2};
			\node [nodestyle,right of=n2] (n3) {3};
			\node [nodestyle,right of=n3] (n4) {3};
			\node [nodestyle,right of=n4] (n5) {2};
			\node [nodestyle, right of=n5] (n6) {1};
			\node [nodestyle, right of=n6] (n7) {null};
			
			\draw[->] (n1) --node[above=0.2cm,align=center] {next} (n2);
			\draw[->] (n2) --node[above=0.2cm,align=center] {next} (n3);
			\draw[->] (n3) --node[above=0.2cm,align=center] {next} (n4);
			\draw[->] (n4) --node[above=0.2cm,align=center] {next} (n5);
			\draw[->] (n5) --node[above=0.2cm,align=center] {next} (n6);
			\draw[->] (n6) --node[above=0.2cm,align=center] {next} (n7);
		\end{scope}
		
	\end{tikzpicture}
	
	\subsubsection{链表中有环}
	
	\begin{tikzpicture}[->,>={Stealth[round]},shorten >=1pt,auto,node distance=2.8cm,on grid,semithick,
		every state/.style={fill=red,draw=none,text=white}]
		\node[initial,state] (A) {$q_a$};
		\node[state] (B) [above right=of A] {$q_b$};
		\node[state] (D) [below right=of A] {$q_d$};
		\node[state] (C) [below right=of B] {$q_c$};
	\end{tikzpicture}
	

	\subsection{双端链表}

	\begin{tikzpicture}[->,>=stealth,node distance=1cm, auto]
	\tikzstyle{nodestyle}=[draw, rectangle, minimum size=1cm, inner sep=0pt]
	
		\node  [nodestyle]  (n) {null};
		\node [nodestyle,right=of n] (n1) {n1};
		\node [nodestyle,right=of n1](n2) {n2};
		\node [nodestyle,right=of n2](n3) {n3};
		\node [nodestyle,right=of n3](n4) {n4};
		\node [nodestyle,right=of n4](n5) {n5};
		\node [nodestyle,right=of n5](n6) {null};
	
		
%\draw[->] (n.north east)    --  node[above=0.2cm, align=center] {next}  (n1.north west);
\draw[->] (n1.north east)	--  node[above=0.2cm, align=center] {next}  (n2.north west);
\draw[->] (n2.north east)	--  node[above=0.2cm, align=center] {next}  (n3.north west);
\draw[->] (n3.north east)	--  node[above=0.2cm, align=center] {next}  (n4.north west);
\draw[->] (n4.north east)	--  node[above=0.2cm, align=center] {next}  (n5.north west);
\draw[->] (n5.north east)	--  node[above=0.2cm, align=center] {next}  (n6.north west);


%\draw[->] (n6.south west) --  node[below=0.2cm, align=center] {pre}  (n5.south east);
\draw[->] (n5.south west) --  node[below=0.2cm, align=center] {pre}  (n4.south east);
\draw[->] (n4.south west) --  node[below=0.2cm, align=center] {pre}  (n3.south east);
\draw[->] (n3.south west) --  node[below=0.2cm, align=center] {pre}  (n2.south east);
\draw[->] (n2.south west) --  node[below=0.2cm, align=center] {pre}  (n1.south east);
\draw[->] (n1.south west) --  node[below=0.2cm, align=center] {pre}  (n.south east);
\end{tikzpicture}


	\subsubsection{链表复制-rand指针}
	
 

